<template>
  <div class="app-container">
    <div style="display:flex;justify-content:space-between;align-items: center;">
      <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
        <el-form-item label="房间" prop="roomName">
          <el-input v-model="queryParams.roomName" placeholder="请输入房间名称" clearable size="small" style="width: 150px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="姓名" prop="userName">
          <el-input v-model="queryParams.userName" placeholder="请输入员工姓名" clearable size="small" style="width: 150px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="handleQuery">搜索</el-button>
          <el-button size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <div style="text-align:right;margin-bottom: 22px;">
        <el-button-group slot="reference">
          <el-button size="small" icon="el-icon-refresh" @click="getList" />
        </el-button-group>
      </div>
    </div>

    <el-table v-loading="loading" border :data="logList" @sort-change="sortChange">
      <el-table-column label="编号" prop="id" width="50" align="center" />
      <el-table-column label="房间" align="center" prop="roomName" />
      <el-table-column label="设备" align="center" prop="serialNumber"></el-table-column>
      <el-table-column label="人员" align="center" prop="userName" />
      <el-table-column label="认证类型" align="center" prop="openType" :formatter="openTypeFormat"></el-table-column>
      <el-table-column label="时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import {
  listLog,
} from "@/api/gate/log";
import { SysCommonStatusEnum } from "@/utils/constants";
import { DICT_TYPE, getDictDataLabel, getDictDatas } from "@/utils/dict";
import { CONSTS, getGateOpenTypeLabel, getGateFactoryCodes } from "@/utils/const";

export default {
  name: "GateLog",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房间表格数据
      logList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 20,
        roomName: undefined,
        userName: undefined,
      },
      // 枚举
      SysCommonStatusEnum: SysCommonStatusEnum,
      // 数据字典
      //门禁品牌
      gateFactoryCodes: getGateFactoryCodes(),
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询日志列表 */
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(
        response => {
          this.logList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    sortChange(column, prop, order) {
      if (column.order === 'ascending') {
        this.queryParams.orderBy = column.prop + ' ' + 'asc'
      } else if (column.order === 'descending') {
        this.queryParams.orderBy = column.prop + ' ' + 'desc'
      } else {
        this.queryParams.orderBy = ''
      }
      this.getList()
    },
    // 开门方式翻译
    openTypeFormat(row, column) {
      return getGateOpenTypeLabel(row.openType)
    },

    //门禁状态翻译
    gateOnlineStatusFormat(row, column) {
      return getGateOnlineStatusLabel(row.onlineState)
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
